﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VanWest.Web.DBAccess;
using System.Net.Mail;

namespace VanWest.Web
{
    public partial class Online_Test : System.Web.UI.Page
    {
        public int ResultCounter
        {
            get
            {
                if (ViewState["ResultCounter"] != null)
                    return Convert.ToInt32(ViewState["ResultCounter"]);
                else
                    return 0;
            }
            set
            {
                ViewState["ResultCounter"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        private void GenerateResults()
        {
            VanWestEntities ctx = new VanWestEntities();
            if (ctx.OnlineTests.Where(o => o.QuestionAnswer == _rbl11.SelectedValue).FirstOrDefault() != null)
                ResultCounter++;
            if (ctx.OnlineTests.Where(o => o.QuestionAnswer == _rbl12.SelectedValue).FirstOrDefault() != null)
                ResultCounter++;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            MultiView1.SetActiveView(View2);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            GenerateResults();
            _lbResult.Text = ResultCounter.ToString();
            if (ResultCounter > 0 && ResultCounter <= 10)
            {
                _lbAdvice.Text = "Please take hahahahaha";
            }
            else if (ResultCounter > 10 && ResultCounter <= 20)
            {
                _lbAdvice.Text = "Please take asd";
            }

            MultiView1.SetActiveView(View10);
        }

        protected void Button2Back_Click(object sender, EventArgs e)
        {
            MultiView1.SetActiveView(View1);
        }

        protected void Button3_Click(object sender, EventArgs e)
        {

        }

        protected void Button3Back_Click(object sender, EventArgs e)
        {

        }

        protected void Button4Back_Click(object sender, EventArgs e)
        {

        }

        protected void Button4_Click(object sender, EventArgs e)
        {

        }

        protected void Button5Back_Click(object sender, EventArgs e)
        {

        }

        protected void Button5_Click(object sender, EventArgs e)
        {

        }

        protected void Button6Back_Click(object sender, EventArgs e)
        {

        }

        protected void Button6_Click(object sender, EventArgs e)
        {

        }

        protected void Button7Back_Click(object sender, EventArgs e)
        {

        }

        protected void Button7_Click(object sender, EventArgs e)
        {

        }

        protected void Button8Back_Click(object sender, EventArgs e)
        {

        }

        protected void Button8_Click(object sender, EventArgs e)
        {

        }

        protected void Button9Back_Click(object sender, EventArgs e)
        {

        }

        protected void Button9_Click(object sender, EventArgs e)
        {

        }

        protected void Button10_Click(object sender, EventArgs e)
        {
            string userName = "it@vanwest.com";
            string password = "vanwest";

            MailMessage message = new MailMessage();
            message.From = new MailAddress("it@vanwest.com");
            message.To.Add(new MailAddress(_tbEmail.Text));

            message.Subject = "This is my subject";
            message.Body = "This is the content";


            MailMessage internalMessage = new MailMessage();
            internalMessage.From = new MailAddress("it@vanwest.com");
            internalMessage.To.Add(new MailAddress("yataopei@hotmail.com"));
            internalMessage.Subject = "This is my subject internal";
            internalMessage.Body = "This is the content";

            System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(userName, password);
            SmtpClient client = new SmtpClient();
            client.UseDefaultCredentials = false;
            client.Credentials = SMTPUserInfo;

            try
            {
                client.Send(message);
                client.Send(internalMessage);
            }
            catch
            {
                _lbsubmitResult.Text = "Send failed!";
            }
            _lbsubmitResult.Text = "Send succeed!";

            MultiView1.SetActiveView(View11);
        }
    }
}